<template>
	<view class="poster_container">
		<image class="img" :src="listImg" mode=""></image>
		<view class="poster_bottom back display align-items justify-content">
			<view class="poster_bottom_top auto" @click="saveImage">保存图片</view>
		</view>
	</view>
</template>
<script>
	var _this
	export default {
		components: {},
		data() {
			return {
				listImg: ''
			}
		},
		onLoad(option) {
			this.imgUrl = this.$imgUrl
			var infoList = option.info.replace(/""/g, "");
			infoList = JSON.parse(decodeURIComponent(infoList))
			this.infoList = infoList
			var id = infoList.id
			var listImg = 'https://miaohuatang.huimaiapp.cn/api/goods/getGoodsImage?id=' + id
			this.listImg = listImg
		},
		methods: {
			saveImage() {
				var url = this.listImg
				uni.downloadFile({
					url,
					success: (resFile) => {
						console.log(resFile, "resFile");
						if (resFile.statusCode === 200) {
							uni.getSetting({
								success: (res) => {
									if (!res.authSetting["scope.writePhotosAlbum"]) {
										uni.authorize({
											scope: "scope.writePhotosAlbum",
											success: () => {
												uni.saveImageToPhotosAlbum({
													filePath: resFile.tempFilePath,
													success: (res) => {
														return uni.showToast({
															title: "保存成功！",
														});
													},
													fail: (res) => {
														return uni.showToast({
															title: res.errMsg,
														});
													},
													complete: (res) => {},
												});
											},
											fail: () => {
												uni.showModal({
													title: "您已拒绝获取相册权限",
													content: "是否进入权限管理，调整授权？",
													success: (res) => {
														if (res.confirm) {
															uni.openSetting({
																success: (res) => {
																	console.log(res.authSetting);
																},
															});
														} else if (res.cancel) {
															return uni.showToast({
																title: "已取消！",
															});
														}
													},
												});
											},
										});
									} else {
										uni.saveImageToPhotosAlbum({
											filePath: resFile.tempFilePath,
											success: (res) => {
												return uni.showToast({
													title: "保存成功！",
												});
											},
											fail: (res) => {
												return uni.showToast({
													title: res.errMsg,
												});
											},
											complete: (res) => {},
										});
									}
								},
								fail: (res) => {},
							});
						} else {
							return uni.showToast({
								title: resFile.errMsg,
							});
						}
					},
					fail: (res) => {
						return uni.showToast({
							title: res.errMsg,
						});
					},
				});


			},
		}
	}
</script>

<style lang="scss" scoped>
	.poster_container {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		height: 100%;
		margin: auto;
		background: #EFF0F2;

		.img {
			width: 360px;
			height: 500px;
			display: block;
			margin: 36rpx auto 0 auto;
		}

		.poster_bottom {
			height: 132rpx;
			padding: 35rpx 0;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			margin: auto;
			border-radius: 10rpx 10rpx 0px 0px;

			.poster_bottom_top {
				width: 440rpx;
				height: 83rpx;
				line-height: 83rpx;
				background: #294D7C;
				border-radius: 4rpx;
				text-align: center;
				font-size: 26rpx;
				color: #fff;
			}

			.poster_bottom_bt {
				width: 440rpx;
				height: 72rpx;
				line-height: 72rpx;
				text-align: center;
				font-size: 26rpx;
				color: #A2A5AA;
			}
		}
	}
</style>
